package cn.fuck;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class TestMeiJuShiTu {
    public static void main(String[] args) {
        Map<Integer, Person> dateTreeMap = new TreeMap<>();
        dateTreeMap.put(1997, new Person(7));
        dateTreeMap.put(1998, new Person(3));
        dateTreeMap.put(1996, new Person(8));
        Set<Integer> keySet = dateTreeMap.keySet();
        keySet.forEach(System.out::println);
        keySet.remove(1998);  // 在key set中删除键时也会会删除值
//        keySet.add(2000);  // 在key set中添加会抛异常

        Collection<Person> people = dateTreeMap.values();
        people.remove(new Person(7));// 在value collection中删除值时就会删除条目
//        people.add(new Person(999));  // 在value collection中添加也会抛异常
        people.forEach(System.out::println);

        // before
        for (Map.Entry<Integer, Person> personEntry : dateTreeMap.entrySet()) {
            Integer year = personEntry.getKey();
            Person p = personEntry.getValue();
            // do sth
        }
        // 1.8
        dateTreeMap.forEach((k, v) -> {
            // do sth
            System.out.println("k: " + k + " v: " + v);
        });
    }
}
